﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Threading;
using System.Text;

namespace LimitOrderBookSim.Commons
{
   public class PerfClock
   {
       [DllImport("Kernel32.dll")]
       private static extern bool QueryPerformanceCounter(out long lpPerformanceCount);

       [DllImport("Kernel32.dll")]
       private static extern bool QueryPerformanceFrequency(out long lpFrequency);

        private long _start;
        private long _stop;
	    private long _freq;
		
    
        public PerfClock()
		{
            _start = 0;
            _stop = 0;

            QueryPerformanceFrequency(out _freq);
		}
		
	
		public void Start()
		{
          
            Thread.Sleep(0);

            QueryPerformanceCounter(out _start);
		}
		
	
		public void Stop()
		{
            QueryPerformanceCounter(out _stop);
		}
		

        public double Duration
        {
        	get
        	{
                return (double)(_stop - _start) / (double)_freq;
            }
        }

    }
}
